package cn.edu.hziee;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "FindServlet",urlPatterns = "/FindServlet")
public class FindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String find = request.getParameter("find");
        HttpSession session = request.getSession();
        Grade grade =new Grade();
        boolean flag =true;
        List<Grade> gradess = new ArrayList<>();
        List<Grade> grades = (List<Grade>) session.getAttribute("card");
        for(int i=0;i<grades.size();i++) {
            grade = grades.get(i);
            if (find.equals(grade.getNumber())) {
                gradess.add(grade);
            }
            else if (find.equals(grade.getName())) {
                gradess.add(grade);
            }
        }
        session.setAttribute("find",gradess);
        response.sendRedirect("/Traversal/find.jsp");

    }
}
